home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10518 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: realloc() -- is there a method for this in c++
  5. Date: 8 Mar 1996 13:40:00 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4hpdbg$k1d@dawn.mmm.com>
  8. References: <4hm5mg$lgl@calvin.cs.ucsb.edu>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Hyun J. Kim (kimhy@cs.ucsb.edu) wrote:
  13. > Hi,
  14.  
  15. > I am trying to change the size of an array dynamically.  In C, using realloc() 
  16. > this is possible.  However, in C++, I am not sure if this is possible using 
  17. > the new operator.  If you have any insight to this problem, please drop me an 
  18. > e-mail.
  19.  
  20. There is no equivalent of realloc in C++ (except realloc itself, of
  21. course :-).  The only safe way to resize an array is to allocate a new
  22. one, copy and delete the old.
  23.  
  24. Unless you're trying to implement one, you could use an array class --
  25. these objects can resize themselves as necessary, managing the memory
  26. for you.
  27. --
  28. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  29. 3M Company                      phone:  (612) 737-4643
  30. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  31. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  32.     But 3M speaks for me -- I did not write the following line:
  33.  
  34. Opinions expressed herein are my own and may not represent those of 3M.
  35.